package eqsolver;

import java.util.Observable;

public class ProxyEquation extends Observable implements IEquation {

	private float[] param;
	private int numberParam;
	IEquation equation;
//	IEquation linearequation;
//	IEquation quadraticequation;

	public ProxyEquation(IEquation equation) {
		this.equation = equation;
		//setEquation(equation.getNumberParam(), equation.getParam());
	}

	public void setEquation(int numberParam, float[] param) {
		this.numberParam = numberParam;
		this.param = param;
		
		update();
		
//		switch (param.length) {
//
//		case 2:
//			IEquation linearequation = new ModelLinearEquation();
//			this.linearequation = linearequation;
//			linearequation.setEquation(numberParam, param);
//			update();
//			break;
//
//		case 3:
//			IEquation quadraticequation = new ModelQuadraticEquation();
//			this.quadraticequation = quadraticequation;
//			quadraticequation.setEquation(numberParam, param);
//			update();
//			break;
//			
//
//		default:
//			// lancia exeption?
//			break;
//		}
		

	}

	public float[] getSol() {
		
		System.out.println("da proxyequation "+this.getParam()[0]+" "+this.getParam()[1]);
		Solver solver  = new Solver(this);
		solver.solve();
		update();
		return solver.getSolution();
		

//		switch (equation.getParam().length) {
//
//		case 2:
//			return linearequation.getSol();
//		case 3:
//			return quadraticequation.getSol();
//
//		default:
//			// lancia exeption?
//			return new float[]{999,999};
//		}
	}
	
	public float[] getParam() {
		
		return param;
		
//		switch (this.getNumberParam()) {
//
//		case 2:
//			return linearequation.getParam();
//		case 3:
//			return quadraticequation.getParam();
//
//		default:
//			// lancia exeption?
//			return new float[]{999,999};
//		}
	}

	public int getNumberParam() {
		return numberParam;
		
	}
	
	public void update(){
		setChanged();
		notifyObservers();
	}

}
